package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartInfoFeignClient;
import com.atguigu.gmall.model.cart.CartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class CartInfoController {
    @Autowired
    private CartInfoFeignClient cartFeignClient;
    //加入购物车  ==添加
    @GetMapping("/addCart.html")
    public String addCart(Long skuId, Integer skuNum, RedirectAttributes redirectAttributes){
        System.out.println("进入添加成功页面");
        cartFeignClient.addToCart(skuId, skuNum);
        redirectAttributes.addAttribute("skuId",skuId);
        redirectAttributes.addAttribute("skuNum",skuNum);
        return "redirect:http://cart.gmall.com/toCart.html";
    }

    //加入购物车  ==查找
    @GetMapping("/toCart.html")
    public String toCart(Long skuId, Integer skuNum, Model model){
        System.out.println("进入查看购物车页面");
        CartInfo cartInfo = cartFeignClient.toCart(skuId);
        cartInfo.setSkuNum(skuNum);
        model.addAttribute("cartInfo",cartInfo);
        return "cart/addCart";
    }

    //去购物车结算
    @GetMapping("/cart.html")
    public String cartList(){


        return "cart/index";
    }
}
